
// pages/errorsAccomplish/errorsAccomplish.js
import api from "../../config/api";
import request from "../../utils/request";
import { shareOptions } from "../../utils/access";
const { getXsScreen, parse } = require("../../utils/utils.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    accomplishData:[],
    knowledgeId:'',
    // 没有题目时显示
    isShow:true,
    // 是否还有数据
    isData:1,
    // 是否是小屏幕尺寸
		...getXsScreen(),
  },
  // 跳转列表页
  goClassify(){
    // wx.redirectTo({
    //   url: '/pages/errorsClassify/errorsClassify',
    // })
    wx.navigateBack({
      delta: 1,
    })
  },
  // 获得错题分类
  async getErrorsData(){
    const num = 0
    const { data } = await request.get(api.getAccomplishList)
    this.setData({
      knowledgeId:data[num].knowledgeId
    })
    // wx.navigateBack({
    //   delta: 1,
    // })
    wx.redirectTo({
      url: `/pages/errorsStoreroom/errorsStoreroom?knowledgeId=${this.data.knowledgeId}`,
    })
  },
  // 跳转到答题页
  async goStoreroom(){
    console.log(this.data.knowledgeId,"老ID")
    const { data } = await request.get(api.getStoreroomList,{
      knowledgeId:this.data.knowledgeId
    })
    // 当题目返回的数据是空时
    if(data.length === 0){
      this.getErrorsData()
    }else{
      wx.redirectTo({
        url: `/pages/errorsStoreroom/errorsStoreroom?knowledgeId=${this.data.knowledgeId}`,
      })
    }
  },
  // 判断是否还有题目
  async getIsErrorsData(){
    const { data } = await request.get(api.getAccomplishList)
    console.log(data)
    if(data.length === 0){
      this.setData({
        isShow:false
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      accomplishData:parse(options.accomplishData),
      knowledgeId:options.knowledgeId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getIsErrorsData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    return shareOptions('default', e)
  }
})